package com.findMoneyGame.models {
	import flash.events.Event;

	import com.findMoneyGame.Engine;
	import com.findMoneyGame.models.Model;
	import com.findMoneyGame.events.UserEvent;

	public class UserData extends Model {
		protected var _level : int;
		protected var _fastCompletedLevelCount : int;
		protected var _moneyCount : int;
		protected var _moneyBought : int;
		protected var _moneySpent : int;
		protected var _timeBonusIndex : int = -1;
		protected var _hintBonusIndex : int = -1;
		protected var _loupeBonusIndex : int = -1;
		protected var _achievement : int;
		protected var _exists : Boolean;


		public function get timeBonusIndex () : int { return _timeBonusIndex; }
		public function get hintBonusIndex () : int { return _hintBonusIndex; }
		public function get loupeBonusIndex () : int { return _loupeBonusIndex; }
		public function get improvementsCount () : int { return timeBonusIndex + 1 + hintBonusIndex + 1 + loupeBonusIndex + 1; }

		public function get level () : int { return _level; }
		public function set level (value : int) { _level = value; dispatchUpdate(); }

		public function get fastCompletedLevelCount () : int { return _fastCompletedLevelCount; }
		public function set fastCompletedLevelCount (value : int) { _fastCompletedLevelCount = value; dispatchUpdate(); }

		public function get season () : int { return int(level / Engine.LEVELS_PER_SEASON); }

		public function get moneyBought () : int { return _moneyBought; }
		public function set moneyBought (value : int) { _moneyBought = value; dispatchUpdate() }

		public function get moneySpent () : int { return _moneySpent; }
		public function set moneySpent (value : int) { _moneySpent = value; dispatchUpdate() }

		public function get moneyCount () : int { return _moneyCount; }
		public function set moneyCount (value : int) { _moneyCount = value; dispatchUpdate(); }

		public function get exists () : Boolean { return _exists; }
		public function set exists (value : Boolean) { _exists = value; }

		public function get achievement () : int { return _achievement; }
		public function set achievement (value : int) { _achievement = value; dispatchUpdate(); }


		public function UserData (id : int = -1) { super(id); }

		public function setNextTimeBonusIndex () { _timeBonusIndex++; dispatchUpdate(); }

		public function setNextHintBonusIndex () { _hintBonusIndex++; dispatchUpdate(); }

		public function setNextLoupeBonusIndex () { _loupeBonusIndex++; dispatchUpdate(); }

		public function incLevel (inc : int = 1) { level += inc; }

		public function addMoney (value : int) { moneyCount += value; }

		public function buyMoney (value : int) {
			_moneyCount += value;
			_moneyBought += value;
			dispatchUpdate();
		}
		public function takeMoney (value : int) {
			_moneyCount -= value;
			_moneySpent += value;
			dispatchUpdate();
		}
		protected override function dispatchUpdate () { super.dispatchStrEvent(UPDATE); }
	}
}